package utils;

import models.common.AuditInfo;
import org.hibernate.event.internal.DefaultSaveOrUpdateEventListener;
import org.hibernate.event.spi.SaveOrUpdateEvent;

import java.util.Date;

/**
 * Created by FireFire on 4/5 0005.
 */
public class SaveOrUpdateListener extends DefaultSaveOrUpdateEventListener{
    @Override
    public void onSaveOrUpdate(SaveOrUpdateEvent event) {
        Object entity = event.getEntity();
        AuditInfo auditInfo = null;
        if(entity instanceof AuditInfo){
            auditInfo = (AuditInfo)entity;
            auditInfo.lastUpdateDate = new Date();
        }

        super.onSaveOrUpdate(event);
    }
}
